package com.example.sls.service.impl.student;

import com.example.sls.mapper.student.StudentMapper;
import com.example.sls.pojo.Class._Class;
import com.example.sls.pojo.student.Student;
import com.example.sls.service.student.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> getStudentsByCId(Integer classId) {
        return studentMapper.getStudentsByCId(classId);
    }

    @Override
    public Boolean addStudent(Student student) {
        boolean flag = false;
        if(studentMapper.addStudent(student) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public Integer getMaxId() {
        return studentMapper.getMaxId();
    }

    @Override
    public Integer getCount() {
        return studentMapper.getCount();
    }

    @Override
    public Student getStudentInfoById(Integer id) {
        return studentMapper.getStudentInfoById(id);
    }

    @Override
    public List<Student> getStudentsInfo() {
        return studentMapper.getStudentsInfo();
    }

    @Override
    public PageInfo<Student> getPageInfoWithoutClass(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Student> students = studentMapper.getStudentWithoutClass();
        return new PageInfo<Student>(students);
    }

    @Override
    public Integer getCountByCId(Integer CId) {
        return studentMapper.getCountByCId(CId);
    }

    @Override
    public Boolean updateCIdBySId(Integer cId, Integer studentId) {
        boolean flag = false;
        if(studentMapper.updateCIdBySId(cId,studentId) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public PageInfo<Student> getPageInfoByCId(Integer cId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Student> students = studentMapper.getStudentsByCId(cId);
        return new PageInfo<Student>(students);
    }

    @Override
    public Boolean leaveClass(Integer studentId) {
        boolean flag = false;
        if(studentMapper.leaveClass(studentId) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public Integer getCIdBySId(Integer studentId) {
        return studentMapper.getCIdBySId(studentId);
    }
}
